<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">

<head>
    <meta charset="UTF-8">
    <title>站点任务</title>
    <link href="__PUBLIC__/layui/css/layui.css" rel="stylesheet" />
    <link rel="stylesheet" href="__PUBLIC__/css/global.css" media="all">
    <link href="__PUBLIC__/Font-Awesome/css/font-awesome.css" rel="stylesheet" />
</head>

<body>
<div class="admin-main">
    <fieldset class="layui-elem-field">
        <legend>任务列表</legend>
        <div class="layui-field-box">
            <table class="layui-table site-table">
                <thead>
                <tr>
                   <!-- <th><input name="sortnum" type="checkbox" id="selected-all"></th>-->
                    <th>任务团队</th>
                    <th style="max-width: 120px;">任务类型</th>
                    <th style="max-width: 120px;">任务执行时间</th>
                    <th>任务状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="listcontent" class="layui-form">
                </tbody>
            </table>
        </div>
    </fieldset>
    <div class="admin-table-page">
        <div id="page" class="page">
        </div>
    </div>
</div>
<script id="demo" type="text/html">
    <tr>
        <td>{{d.t_name }}</td>
        <td>{{d.tasktype}}</td>
        <td>
            {{# if(d.status == 2){ }} <span>结束</span> {{# } if(d.status == 1){ }} <span>等待脚本调用</span>{{# } if(d.status == 4){ }} <span>定时任务执行中</span> {{# } }}
        </td>
        <td>
            {{# if(d.status == 4){ }}
            <a  data="{{d.task_relid}}" class="layui-btn layui-btn-normal layui-btn-mini stop"><i class="layui-icon">&#x1006;</i>结束并删除任务</a>
            {{#} }}
        </td>
    </tr>
</script>
<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>

<script>
    var addurl="{:U('MyTeam/timeTaskAdd')}"
    var form,layer,$,laydate;

    layui.use(['layer', 'form','laypage','laytpl','laydate'], function () {
        var laypage = layui.laypage,laytpl = layui.laytpl;
        laydate = layui.laydate;
        form = layui.form();
        $ = layui.jquery
        layer=layui.layer;
        var pagelistdate;
        var curr;
        form.render();
        laypage({
            cont: 'page',
            pages: {$page} //总页数
            ,
            groups: 5 //连续显示分页数
            ,

            jump: function(obj, first) {
                curr = obj.curr;
                listcontent.innerHTML='';
                $.ajax({
                    type: "GET",
                    url: "",
                    data: { p:curr},
                    async: false,
                    success: function(date){
                        if(date['code']==101) {
                            pagelistdate =date .data;
                            var getTpl = demo.innerHTML;
                            layui.each(date.data, function (k, v) {
                                laytpl(getTpl).render(v, function (html) {
                                    listcontent.innerHTML += html;
                                });
                            });
                        }
                    }
                });

                caozuo();
                form.render();
            }
        });




        function caozuo(){
            $('.del').click(function () {
                var id = $(this).attr('data');
                var url = "{:U('MyTeam/deletaskrel')}";
                layer.confirm('确定删除吗', {
                    icon: 3,
                    skin: 'layer-ext-moon',
                    btn: ['确认','取消']
                }, function(){
                    $.post(url,{keyid:id},function(data){
                        if(data.code=='4001'){
                            layer.msg(data.msg,{icon: 5});
                        }else{
                            layer.msg(data.msg, {
                                icon: 6,
                                time: 2000
                            }, function(){
                                window.location.reload();
                            });
                        }
                    });
                });
            });
            $('.stop').click(function(){
                var id = $(this).attr('data');
                var url = "{:U('MyTeam/stopTaskrel')}";
                layer.confirm('确定终止该任务吗,终止之后不会有新的订单产生', {
                    icon: 3,
                    skin: 'layer-ext-moon',
                    btn: ['确认','取消']
                }, function(){
                    $.post(url,{keyid:id},function(data){
                        if(data.code=='4001'){
                            layer.msg(data.msg,{icon: 5});
                        }else{
                            layer.msg(data.msg, {
                                icon: 6,
                                time: 2000
                            }, function(){
                                window.location.reload();
                            });
                        }
                    });
                });
            });
            $('.create').click(function(){
                var id = $(this).attr('data');
                var url = "{:U('MyTeam/starttask')}";
                $.post(url,{keyid:id},function(data){
                    if(data.code=='4001'){
                        layer.msg(data.msg,{icon: 5});
                    }else{
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 2000
                        }, function(){
                            window.location.reload();
                        });
                    }
                });

            });
        }
    });
</script>
</body>

</html>